package org.jsbd.boss.action;

import java.util.HashMap;
import java.util.Map;

import org.jsbd.boss.service.IExtractingDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.common.utils.StringUtils;

/**
 * 提取数据controller
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/extractingData")
public class ExtractingDataController {
	
	@Autowired
	private IExtractingDataService extractingDataService;
	
	/**
	 * 列表页面
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "listModel")
	public String showEmailGroupList(Model model) throws Exception {
		return "/extractingData/extractingDataIndex";
	}
	
	/**
	 * 提取数据列表
	 * @param tableName
	 * @return
	 */
	@RequestMapping(value = "getData")
	@ResponseBody
	public Map<String, Object> getData(Integer page, Integer rows, String tableName, String startTime, String endTime){
		if (page == null) {
			page = 1;
		}
		if (rows == null) {
			rows = 100;
		}
		Map<String, Object> result = new HashMap<>();
		if (StringUtils.isBlank(tableName)) {
			result.put("success", false);
			result.put("msg", "未输入表名");
		    return result;
		}
		result  = extractingDataService.getExtractData(page, rows, tableName, startTime, endTime);
		if (result == null) {
			result = new HashMap<>();
			result.put("success", false);
			result.put("msg", "此表不存在");
		    return result;
		}
		result.put("rowsValue", rows);
		result.put("pageValue", page);
		result.put("success", true);
		result.put("msg", "查询成功");
	    return result;
	}

}
